<template>
	<view class="container">
		<!-- 顶部导航栏 -->
		<u-navbar title="合同服务" :autoBack="true" :fixed="true" :bgColor="'#ffffff'" :placeholder="true" :titleStyle="{
        color: '#333',
        fontSize: '16px',
      }"></u-navbar>
		<view class="status">{{ contractInfo.status_text }}</view>
		<!-- 表单内容 -->
		<view class="form-content">
			<!-- 租期信息 -->
			<view class="form-section">
				<view class="section-title">房屋信息</view>
        <view class="form-item">
          <text class="label">楼栋名称</text>
          <text class="value">{{ contractInfo.build_name }}</text>
        </view>
				<view class="form-item">
					<text class="label">楼栋地址</text>
					<text class="value">{{ contractInfo.house_address }}</text>
				</view>
				<view class="form-item">
					<text class="label">房间</text>
					<text class="value">{{ contractInfo.room_name }}</text>
				</view>
			</view>
			<!-- 租期信息 -->
			<view class="form-section">
				<view class="section-title">租期信息</view>
				<view class="form-item">
					<text class="label">租期开始时间</text>
					<text class="value">
						{{
              contractInfo.start_time
                ? contractInfo.start_time.split(" ")[0]
                : ""
            }}
					</text>
				</view>
				<view class="form-item">
					<text class="label">租期截止时间</text>
					<text class="value">
						{{
              contractInfo.end_time ? contractInfo.end_time.split(" ")[0] : ""
            }}
					</text>
				</view>
			</view>
			<!-- 租金与押金 -->
			<view class="form-section">
				<view class="section-title">租金与押金</view>
				<view class="form-item">
					<text class="label">租金</text>
					<view class="value">
						<text>{{ contractInfo.money_zu }}元/月</text>
					</view>
				</view>
<!--				<view class="form-item">-->
<!--					<text class="label">押金方式</text>-->
<!--					<view class="value">-->
<!--						<text>{{ contractInfo.ya_type_text }}</text>-->
<!--					</view>-->
<!--				</view>-->
				<view class="form-item">
					<text class="label">押金金额</text>
					<view class="value">
						<text>{{ contractInfo.money_ya }}元</text>
					</view>
				</view>
			</view>

			<!-- 合同附件 -->
			<!-- <view class="form-section" style="overflow: hidden">
        <view class="attachment-header">
          <view class="section-title" style="margin-bottom: 0; padding: 0">
            合同附件
          </view>
          <view class="upload-btn">
            <u-switch v-model="value" @change="change"></u-switch>
          </view>
        </view>
        <view class="attachment-list" @click="handleNext" v-if="value">
          <u-icon name="attach" color="#0095f8" size="20"></u-icon>
          <view class="attachment-name">房屋租赁合同</view>
          <u-icon name="arrow-right" color="#999" size="16"></u-icon>
        </view>
      </view> -->
			<!-- 图片 -->
			<view class="form-section">
				<view class="section-title">签名</view>
				<view class="photo-box">
					<image :src="contractInfo.user_sign_img" :key="index" @click="previewImage(contractInfo.user_sign_img)"
						></image>
				</view>
			</view>
		</view>

		<!-- 底部按钮组 -->
		<!-- <view class="bottom-btns">
			<view class="btn next" @click="handleNext">查看附件</view>
		</view> -->
	</view>
</template>

<script>
	import {
		LeaseDetail,
		LeaseDetailUser
	} from "@/api/lease.js";
	export default {
		data() {
			return {
				value: false,
				contract_id: "",
				contractInfo: {},
			};
		},
		onLoad(e) {
			this.contract_id = e.id;
			this.getDetail();
		},
		methods: {
			change(e) {
				console.log(e);
				this.value = e;
			},
			handlePrev() {
				uni.navigateBack();
			},
			previewImage(item) {
				uni.previewImage({
					current: item, // 当前显示图片的http链接
					urls: this.contractInfo.photo, // 需要预览的图片http链接列表
				});
			},
			handleNext() {
				uni.downloadFile({
					url: this.contractInfo.attachment[0],
					success: function(res) {
						console.log(res);
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log("打开文档成功");
							},
						});
					},
				});
			},
			getDetail() {
				LeaseDetailUser({
					id: this.contract_id,
				}).then((res) => {
					this.contractInfo = res.data.data;
				});
			},
		},
	};
</script>

<style lang="less" scoped>
	.container {
		min-height: 100vh;
		background: #f5f6fa;
	}

	.status {
		width: 750rpx;
		height: 74rpx;
		text-align: center;
		line-height: 74rpx;
		background: #81b336;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #ffffff;
		margin-bottom: 24rpx;
	}

	.nav-right {
		font-size: 28rpx;
		color: #2979ff;
		padding: 0 32rpx;
	}

	.form-content {
		padding: 0 24rpx 40rpx;

		.section-title {
			padding-top: 24rpx;
			font-size: 28rpx;
			color: #333;
			margin-bottom: 24rpx;
		}
	}

	.form-section {
		background: #fff;
		border-radius: 12rpx;
		padding: 0 24rpx;
		margin-bottom: 24rpx;

		.form-item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			min-height: 88rpx;
			border-bottom: 2rpx solid #f5f5f5;

			&:last-child {
				border-bottom: none;
			}

			.label {
				font-size: 28rpx;
				color: rgba(102, 102, 102, 1);
			}

			.value {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				color: rgba(34, 34, 34, 1);
				text-align: right;

				.unit {
					font-size: 24rpx;
					color: #999;
					margin-left: 4rpx;
				}
			}
		}

		.photo-box {
			display: flex;
			flex-wrap: wrap;
			gap: 16rpx;

			image {
				width: 144rpx;
				height: 144rpx;
				border-radius: 8rpx;
			}
		}

		.attachment-header {
			padding: 24rpx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.attachment-list {
			padding: 0 20rpx;
			height: 80rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background: #2979ff1a;
			margin-bottom: 20rpx;
			border-radius: 10rpx;

			.attachment-name {
				flex: 1;
				font-size: 26rpx;
				color: #333;
			}
		}
	}

	.bottom-btns {
		padding: 24rpx;
		display: flex;
		justify-content: space-between;
		padding-bottom: calc(24rpx + env(safe-area-inset-bottom));

		.btn {
			width: 100%;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			border-radius: 44rpx;
			font-size: 32rpx;

			&.prev {
				color: #2979ff;
				background: #fff;
				border: 2rpx solid #2979ff;
			}

			&.next {
				color: #fff;
				background: #2979ff;
			}
		}
	}
</style>